package com.ego.controller;

import com.ego.pojo.Cart;
import com.ego.pojo.Foot;
import com.ego.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * @author Ares
 * @date 2020-12-10
 */
@Controller
public class CartController {

    @Autowired
    private CartService cartService;

    /**
     * 添加购物车
     *
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> addCart(@RequestBody Cart cart) {
        this.cartService.addCart(cart);
        return ResponseEntity.ok().build();
    }

    @GetMapping
    public ResponseEntity<List<Cart>> queryCart(@CookieValue("EGO_TOKEN") String token){
        List<Cart> result = cartService.findCart(token);
        return ResponseEntity.ok(result);
    }

    @PostMapping("foot")
    public ResponseEntity<Integer> addFoot(@RequestBody Foot foot) {
        Integer i = cartService.addFoot(foot);
        return ResponseEntity.ok(i);
    }

    @GetMapping("foots")
    public ResponseEntity<List<Foot>> queryFoot(@CookieValue("EGO_TOKEN") String token){
        List<Foot> result = cartService.findFoot(token);
        return ResponseEntity.ok(result);
    }
}
